package com.wn.controller;

import com.wn.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Docter
 * @date 2022 -07-12
 * @desc
 *
 *  01 每个方法都有  @ResponseBody
 *    优化: @RestController = @Controller  + @ResponseBody
 *
 *  02 每个方法都有  @RequestMapping(value = "/users")
 *     优化: 把url直接写到类上面: @RequestMapping("/users")
 *
 *  03  @PostMapping =   @RequestMapping(method = RequestMethod.POST)
 */
@RestController //每个方法都有   @ResponseBody
@RequestMapping("/users2")
public class User2Controller {

    /**
     * 保存
     * @param user
     * @return
     */
    @PostMapping
    public String save(@RequestBody User user) {
        System.out.println("user save..."+user);
        return "{'module':'user save'}";
    }

    /**
     * 删除的时候 需要携带参数:
     *
     * 路径参数:
     *    /xxx/{id}
     *
     *  获取参数:
     *   @PathVariable  获取路径参数 (路径 参数 )
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}")
    public String delete(@PathVariable Integer id) {
        System.out.println("user delete..." + id);
        return "{'module':'user delete'}";
    }

    @PutMapping
    public String update(@RequestBody User user) {
        System.out.println("user update..." + user);
        return "{'module':'user update'}";
    }

    @GetMapping(value = "/{id}")
    public String getById(@PathVariable Integer id) {
        System.out.println("user getById..." + id);
        return "{'module':'user getById'}";
    }

}
